package org.jtb.quickr;

import java.net.MalformedURLException;
import java.net.URL;
import org.apache.log4j.Logger;

class BuddyIconUrl extends FlickrUrl {
    private static Logger logger = Logger.getLogger(BuddyIconUrl.class.getName());
    public static URL DEFAULT_BUDDY_ICON_URL;

    static {
        try {
            DEFAULT_BUDDY_ICON_URL = new URL("http://www.flickr.com/images/buddyicon.jpg");
        } catch (MalformedURLException mfue) {
            throw new RuntimeException("could not construct default buddy icon URL");
        }
    }
    
    private int iconServer;
    private String nsId;
    
    /**
     * Construct a buddy icon URL.
     */
    public BuddyIconUrl(String staticUrl, int iconServer, String nsId) throws QuickrException {
        super(staticUrl);
        this.iconServer = iconServer;
        this.nsId = nsId;
    }
    
    
    protected URL buildUrl() throws QuickrException {
        if (iconServer == 0) {
            return DEFAULT_BUDDY_ICON_URL;
        } else {
            String u = getBaseUrl() + "/" + iconServer + "/buddyicons/" + nsId + ".jpg";
            try {
                return new URL(u);
            } catch (MalformedURLException mfue) {
                throw new QuickrException("could not create buddy icon URL", mfue);
            }
        }
    }
}
